<?php

namespace app\admin\controller\business;


use app\admin\model\business\StashDetail;
use app\common\controller\Backend;

class Allot extends Backend
{
    /**
     * Notes: 调拨单
     * User: AerYYY
     * Date: 2/16/24 3:31 PM
     * @return string
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function create()
    {
        if ($this->request->isPost()) {
            $params = $this->request->post();
            $params['admin_id'] = $this->auth->id;


            $stashDetailModel = new StashDetail();
            $stashDetailModel->startTrans();
            if ($stashDetailModel->allotCreate($params)) {
                $stashDetailModel->commit();
                $this->success('ok');
            }
            $stashDetailModel->rollback();
            $this->error($stashDetailModel->getError());
        }

        $order_no = order_no('TD');
        $this->assign('order_no', $order_no);
        return $this->view->fetch();
    }

    /**
     * Notes: 其他入库单
     * User: AerYYY
     * Date: 2/16/24 3:49 PM
     * @return string
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    public function other_warehousing()
    {
        if ($this->request->isPost()) {
            $params = $this->request->post();
            $params['admin_id'] = $this->auth->id;


            $stashDetailModel = new StashDetail();
            $stashDetailModel->startTrans();
            if ($stashDetailModel->other_warehousing($params)) {
                $stashDetailModel->commit();
                $this->success('ok');
            }
            $stashDetailModel->rollback();
            $this->error($stashDetailModel->getError());
        }

        $order_no = order_no('QTR');
        $this->assign('order_no', $order_no);
        return $this->view->fetch();
    }



    public function other_outbound()
    {
        if ($this->request->isPost()) {
            $params = $this->request->post();
            $params['admin_id'] = $this->auth->id;


            $stashDetailModel = new StashDetail();
            $stashDetailModel->startTrans();
            if ($stashDetailModel->other_outbound($params)) {
                $stashDetailModel->commit();
                $this->success('ok');
            }
            $stashDetailModel->rollback();
            $this->error($stashDetailModel->getError());
        }

        $order_no = order_no('QTC');
        $this->assign('order_no', $order_no);
        return $this->view->fetch();
    }
}